#!/bin/bash
MASK_24="255.255.255.0"
MASK_25="255.255.255.128"
MASK_26="255.255.255.192"
MASK_27="255.255.255.224"
MASK_28="255.255.255.240"
MASK_29="255.255.255.248"
MASK_30="255.255.255.252"

IP_DNSROOT="10.47.1.131"
BROADCAST_DNSROOT="10.47.1.191"
MASCARA_DNSROOT="255.255.255.192"

IP_DNS1="10.118.5.31"
BROADCAST_DNS1="10.118.5.255"
MASCARA_DNS1="255.255.255.0"

IP_DNS2="10.19.2.2"
BROADCAST_DNS2="10.19.2.127"
MASCARA_DNS2="255.255.255.128"

RED_A="10.118.5.0"
RED_B="10.19.2.128"
RED_C="192.168.71.0"
RED_D="172.143.0.64"
RED_E="10.19.2.0"
RED_F="10.47.3.32"
RED_G="10.19.2.128"
RED_H="10.19.2.192"
RED_I="10.47.1.128"
RED_J="10.47.2.0"
RED_K="10.19.2.160"
RED_L="133.143.1.4"
RED_M="133.143.1.8"
RED_N="10.47.3.64"
RED_O="10.19.2.224"
RED_P="10.19.2.136"
RED_Q="10.19.2.140"
RED_R="10.19.2.144"
RED_S="10.19.2.148"
RED_T="133.143.1.0"

function DNS1 {
	ifconfig $interfaz $IP_DNS1 broadcast $BROADCAST_DNS1 netmask $MASCARA_DNS1
	route add -net 10.118.5.0/24 dev $interfaz
	route add -net $RED_B netmask $MASK_29 gw 10.118.5.2 dev $interfaz
	route add -net $RED_C netmask $MASK_24 gw 10.118.5.3 dev $interfaz
	route add -net $RED_D netmask $MASK_26 gw 10.118.5.1 dev $interfaz
	route add -net $RED_E netmask $MASK_25 gw 10.118.5.1 dev $interfaz
	route add -net $RED_F netmask $MASK_27 gw 10.118.5.1 dev $interfaz
	route add -net $RED_G netmask $MASK_29 gw 10.118.5.1 dev $interfaz
	route add -net $RED_H netmask $MASK_27 gw 10.118.5.1 dev $interfaz
	route add -net $RED_I netmask $MASK_26 gw 10.118.5.1 dev $interfaz
	route add -net $RED_J netmask $MASK_24 gw 10.118.5.1 dev $interfaz
	route add -net $RED_K netmask $MASK_27 gw 10.118.5.2 dev $interfaz
	route add -net $RED_L netmask $MASK_30 gw 10.118.5.2 dev $interfaz
	route add -net $RED_M netmask $MASK_30 gw 10.118.5.1 dev $interfaz
	route add -net $RED_N netmask $MASK_28 gw 10.118.5.2 dev $interfaz
	route add -net $RED_O netmask $MASK_28 gw 10.118.5.1 dev $interfaz
	route add -net $RED_P netmask $MASK_30 gw 10.118.5.1 dev $interfaz
	route add -net $RED_Q netmask $MASK_30 gw 10.118.5.1 dev $interfaz
	route add -net $RED_R netmask $MASK_30 gw 10.118.5.1 dev $interfaz
	route add -net $RED_S netmask $MASK_30 gw 10.118.5.1 dev $interfaz
	route add -net $RED_T netmask $MASK_30 gw 10.118.5.3 dev $interfaz
	echo "nameserver $IP_DNSROOT" > /etc/resolv.conf
	cp dns1/* /etc/bind
	/etc/init.d/bind9 restart
}

function DNS2 {
	ifconfig $interfaz $IP_DNS2 broadcast $BROADCAST_DNS2 netmask $MASCARA_DNS2
	route add -net 10.19.2.0/25 dev $interfaz
	route add -net $RED_A netmask $MASK_24 gw 10.19.2.12 dev $interfaz
	route add -net $RED_B netmask $MASK_29 gw 10.19.2.10 dev $interfaz
	route add -net $RED_C netmask $MASK_24 gw 10.19.2.12 dev $interfaz
	route add -net $RED_D netmask $MASK_26 gw 10.19.2.12 dev $interfaz
	route add -net $RED_F netmask $MASK_27 gw 10.19.2.10 dev $interfaz
	route add -net $RED_G netmask $MASK_29 gw 10.19.2.11 dev $interfaz
	route add -net $RED_H netmask $MASK_27 gw 10.19.2.11 dev $interfaz
	route add -net $RED_I netmask $MASK_26 gw 10.19.2.10 dev $interfaz
	route add -net $RED_J netmask $MASK_24 gw 10.19.2.11 dev $interfaz
	route add -net $RED_K netmask $MASK_27 gw 10.19.2.10 dev $interfaz
	route add -net $RED_L netmask $MASK_30 gw 10.19.2.10 dev $interfaz
	route add -net $RED_M netmask $MASK_30 gw 10.19.2.11 dev $interfaz
	route add -net $RED_N netmask $MASK_28 gw 10.19.2.10 dev $interfaz
	route add -net $RED_O netmask $MASK_28 gw 10.19.2.11 dev $interfaz
	route add -net $RED_P netmask $MASK_30 gw 10.19.2.11 dev $interfaz
	route add -net $RED_Q netmask $MASK_30 gw 10.19.2.11 dev $interfaz
	route add -net $RED_R netmask $MASK_30 gw 10.19.2.11 dev $interfaz
	route add -net $RED_S netmask $MASK_30 gw 10.19.2.11 dev $interfaz
	route add -net $RED_T netmask $MASK_30 gw 10.19.2.12 dev $interfaz
	echo "nameserver $IP_DNSROOT" > /etc/resolv.conf
	cp dns2/* /etc/bind
	/etc/init.d/bind9 restart
}

function DNSROOT {
	ifconfig $interfaz $IP_DNSROOT broadcast $BROADCAST_DNSROOT netmask $MASCARA_DNSROOT
	route add -net 10.47.1.128/26 dev $interfaz
	route add -net $RED_B netmask $MASK_29 gw 10.47.1.132 dev $interfaz
	route add -net $RED_C netmask $MASK_24 gw 10.47.1.132 dev $interfaz
	route add -net $RED_D netmask $MASK_26 gw 10.47.1.132 dev $interfaz
	route add -net $RED_E netmask $MASK_25 gw 10.47.1.132 dev $interfaz
	route add -net $RED_F netmask $MASK_27 gw 10.47.1.132 dev $interfaz
	route add -net $RED_G netmask $MASK_29 gw 10.47.1.132 dev $interfaz
	route add -net $RED_H netmask $MASK_27 gw 10.47.1.132 dev $interfaz
	route add -net $RED_I netmask $MASK_26 gw 10.47.1.132 dev $interfaz
	route add -net $RED_J netmask $MASK_24 gw 10.47.1.132 dev $interfaz
	route add -net $RED_K netmask $MASK_27 gw 10.47.1.132 dev $interfaz
	route add -net $RED_L netmask $MASK_30 gw 10.47.1.132 dev $interfaz
	route add -net $RED_M netmask $MASK_30 gw 10.47.1.132 dev $interfaz
	route add -net $RED_N netmask $MASK_28 gw 10.47.1.132 dev $interfaz
	route add -net $RED_O netmask $MASK_28 gw 10.47.1.132 dev $interfaz
	route add -net $RED_P netmask $MASK_30 gw 10.47.1.132 dev $interfaz
	route add -net $RED_Q netmask $MASK_30 gw 10.47.1.132 dev $interfaz
	route add -net $RED_R netmask $MASK_30 gw 10.47.1.132 dev $interfaz
	route add -net $RED_S netmask $MASK_30 gw 10.47.1.132 dev $interfaz
	route add -net $RED_T netmask $MASK_30 gw 10.47.1.132 dev $interfaz
	echo "nameserver 127.0.0.1" > /etc/resolv.conf
	cp dnsroot/* /etc/bind
	/etc/init.d/bind9 restart
}

interfaz=$2

case $1 in
	dns1)
		echo "DNS 1"
		DNS1
	;;
	dns2)
		echo "DNS 2"
		DNS2
	;;
	dnsroot)
        echo "DNS ROOT"
		DNSROOT
	;;
esac

